package com.caiwangdai.app.ui.verify

import android.Manifest
import android.content.Context
import android.content.Intent
import com.caiwangdai.app.R
import com.caiwangdai.app.extension.setOnClickListenerPro
import com.caiwangdai.app.extension.showMissingPermissionDialog
import com.caiwangdai.app.origin.BaseActivity
import com.caiwangdai.app.origin.ToolBarManager
import com.tbruyelle.rxpermissions2.RxPermissions
import kotlinx.android.synthetic.main.activity_face_verify_ready.*

/**
 * 人脸识别认证-准备界面
 */
class FaceVerifyReadyActivity : BaseActivity() {

    override fun getLayoutResID() = R.layout.activity_face_verify_ready

    companion object {
        fun newInstance(context: Context): Intent {
            val intent = Intent(context, FaceVerifyReadyActivity::class.java)
            return intent
        }
    }

    override fun initView() {
        ToolBarManager.with(this, WMContent)
                .setTitle("")
                .setBackgroundColor(R.color.white)
                .setNavigationIcon(R.drawable.ic_nav_close_circle)

        btn_verify.setOnClickListenerPro {
            RxPermissions(this)
                    .request(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
                    .subscribe { granted ->
                        if (granted!!) {
                            startActivity(FaceCameraActivity.newInstance(mContext))
                            onBackPressed()
                        } else {
                            showMissingPermissionDialog("没有此权限，APP将无法正常访问摄像头!")
                        }
                    }

        }
    }

    override fun onBackPressed() {
        super.onBackPressed()
        overridePendingTransition(-1, R.anim.slide_out_from_bottom);
    }
}
